﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace NCKH.Admin
{
    public partial class suanhomtin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                if (Request.QueryString["pid"] != null)
                {
                    int nhomtinID = Convert.ToInt32(Request.QueryString["pid"]);
                    hiennhomtin(nhomtinID);
                }
        }
        protected void hiennhomtin(int nhomtinID)
        {
            string connectionstring = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            string select_nhomtin = "SELECT Manhomtin, Tennhomtin FROM NHOMTIN WHERE Manhomtin='" + nhomtinID + "'";
            using (SqlConnection cnn = new SqlConnection(connectionstring))
            {
                using (SqlCommand cmd = new SqlCommand(select_nhomtin, cnn))
                {
                    cmd.CommandType = CommandType.Text;
                    cnn.Open();
                    using (SqlDataReader rd = cmd.ExecuteReader())
                    {
                        if (rd.HasRows && rd.Read())
                        {
                            txtma.Text = rd["Manhomtin"].ToString();
                            txtten.Text = rd["Tennhomtin"].ToString();
                            btsua.CommandArgument = nhomtinID.ToString();
                        }
                        rd.Close();
                    }
                    cnn.Close();
                }
            }
        }

        protected void btsua_Click(object sender, EventArgs e)
        {
            string connectionstring = ConfigurationManager.ConnectionStrings["NCKH"].ConnectionString;
            using (SqlConnection cnn = new SqlConnection(connectionstring))
            {
                using (SqlCommand cmd = new SqlCommand("capnhatnhomtin", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("Manhomtin", btsua.CommandArgument);
                    cmd.Parameters.AddWithValue("Tennhomtin", txtten.Text);
                    cnn.Open();
                    cmd.ExecuteNonQuery();
                    cnn.Close();
                }
            }
            Response.Redirect("nhomtin.aspx");
        }

        protected void btback_Click(object sender, EventArgs e)
        {
            Response.Redirect("nhomtin.aspx");
        }

        protected void txtten_TextChanged(object sender, EventArgs e)
        {

        }
    }
}